/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Beans;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Thiago
 */
@Entity
@Table(name = "cliente", catalog = "trust", schema = "")
/*
@NamedQueries({
    @NamedQuery(name = "Cliente.findAll", query = "SELECT c FROM Cliente c"),
    @NamedQuery(name = "Cliente.findByIdcliente", query = "SELECT c FROM Cliente c WHERE c.idcliente = :idcliente"),
    @NamedQuery(name = "Cliente.findByNomeCliente", query = "SELECT c FROM Cliente c WHERE c.nomeCliente = :nomeCliente"),
    @NamedQuery(name = "Cliente.findByCpfCliente", query = "SELECT c FROM Cliente c WHERE c.cpfCliente = :cpfCliente"),
    @NamedQuery(name = "Cliente.findByCelCliente", query = "SELECT c FROM Cliente c WHERE c.celCliente = :celCliente"),
    @NamedQuery(name = "Cliente.findByFixoCliente", query = "SELECT c FROM Cliente c WHERE c.fixoCliente = :fixoCliente"),
    @NamedQuery(name = "Cliente.findByEmailCliente", query = "SELECT c FROM Cliente c WHERE c.emailCliente = :emailCliente"),
    @NamedQuery(name = "Cliente.findByObsCliente", query = "SELECT c FROM Cliente c WHERE c.obsCliente = :obsCliente"),
    @NamedQuery(name = "Cliente.findByStatusCliente", query = "SELECT c FROM Cliente c WHERE c.statusCliente = :statusCliente"),
    @NamedQuery(name = "Cliente.findByEndereco", query = "SELECT c FROM Cliente c WHERE c.endereco = :endereco")})
*/
public class Cliente implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idcliente")
    private Integer idcliente;
    @Basic(optional = false)
    @Column(name = "nomeCliente")
    private String nomeCliente;
    @Column(name = "cpfCliente")
    private String cpfCliente;
    @Column(name = "celCliente")
    private String celCliente;
    @Column(name = "fixoCliente")
    private String fixoCliente;
    @Column(name = "emailCliente")
    private String emailCliente;
    @Column(name = "obsCliente")
    private String obsCliente;
    @Column(name = "statusCliente")
    private String statusCliente;
    
    @OneToOne(cascade = CascadeType.ALL)
    @Basic(optional = false)
    @JoinColumn(name = "idendereco")
    private Endereco endereco;
    
    @OneToMany(mappedBy = "cliente")
    private List<Compra> compras = new ArrayList<>();

    public Cliente() {
    }

    public Cliente(Integer idcliente) {
        this.idcliente = idcliente;
    }

    public Cliente(Integer idcliente, String nomeCliente, Endereco endereco, List<Compra> compras) {
        this.idcliente = idcliente;
        this.nomeCliente = nomeCliente;
        this.endereco = endereco;
        this.compras =compras;
    }

    public Integer getIdcliente() {
        return idcliente;
    }

    public void setIdcliente(Integer idcliente) {
        Integer oldIdcliente = this.idcliente;
        this.idcliente = idcliente;
        changeSupport.firePropertyChange("idcliente", oldIdcliente, idcliente);
    }

    public String getNomeCliente() {
        return nomeCliente;
    }

    public void setNomeCliente(String nomeCliente) {
        String oldNomeCliente = this.nomeCliente;
        this.nomeCliente = nomeCliente;
        changeSupport.firePropertyChange("nomeCliente", oldNomeCliente, nomeCliente);
    }

    public String getCpfCliente() {
        return cpfCliente;
    }

    public void setCpfCliente(String cpfCliente) {
        String oldCpfCliente = this.cpfCliente;
        this.cpfCliente = cpfCliente;
        changeSupport.firePropertyChange("cpfCliente", oldCpfCliente, cpfCliente);
    }

    public String getCelCliente() {
        return celCliente;
    }

    public void setCelCliente(String celCliente) {
        String oldCelCliente = this.celCliente;
        this.celCliente = celCliente;
        changeSupport.firePropertyChange("celCliente", oldCelCliente, celCliente);
    }

    public String getFixoCliente() {
        return fixoCliente;
    }

    public void setFixoCliente(String fixoCliente) {
        String oldFixoCliente = this.fixoCliente;
        this.fixoCliente = fixoCliente;
        changeSupport.firePropertyChange("fixoCliente", oldFixoCliente, fixoCliente);
    }

    public String getEmailCliente() {
        return emailCliente;
    }

    public void setEmailCliente(String emailCliente) {
        String oldEmailCliente = this.emailCliente;
        this.emailCliente = emailCliente;
        changeSupport.firePropertyChange("emailCliente", oldEmailCliente, emailCliente);
    }

    public String getObsCliente() {
        return obsCliente;
    }

    public void setObsCliente(String obsCliente) {
        String oldObsCliente = this.obsCliente;
        this.obsCliente = obsCliente;
        changeSupport.firePropertyChange("obsCliente", oldObsCliente, obsCliente);
    }

    public String getStatusCliente() {
        return statusCliente;
    }

    public void setStatusCliente(String statusCliente) {
        String oldStatusCliente = this.statusCliente;
        this.statusCliente = statusCliente;
        changeSupport.firePropertyChange("statusCliente", oldStatusCliente, statusCliente);
    }

    public Endereco getEndereco() {
        return endereco;
    }

    public void setEndereco(Endereco endereco) {
        Endereco oldendereco = this.endereco;
        this.endereco = endereco;
        changeSupport.firePropertyChange("endereco", oldendereco, endereco);
    }
     
    public  List<Compra> getCompras() {
        return compras;
    }

    public void setCompras(List<Compra> compras) {
        List<Compra> oldCompras = this.compras;
        this.compras = compras;
        changeSupport.firePropertyChange("compras", oldCompras, compras);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idcliente != null ? idcliente.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cliente)) {
            return false;
        }
        Cliente other = (Cliente) object;
        if ((this.idcliente == null && other.idcliente != null) || (this.idcliente != null && !this.idcliente.equals(other.idcliente))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "View.Cliente[ idcliente=" + idcliente + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
